import httpRequest from '@/http/request'
import { reactive, ref } from 'vue'
interface EquipmentListParm {
    id: string;
    pid: number;
    type: string;
    state: string;
    message: string;
    // gmtCreate: null;
    // gmtModified: string
}
interface aquariumMessageParm {
    charge: string;
    fishNum: number;
    phone: string;
    value1: string;
    value2: string;
    value3: string;
    value4: string;
    value5: string;
}

export async function ApiGetBar() {
    let aquarium = sessionStorage.getItem('aquarium')
    let fishCountVo = reactive({ xaxis: [], yaxis: [] })
    await httpRequest.get(`/web/index/fishCountSta/${aquarium}/7`).then((res) => {
        fishCountVo = res.data.data.fishCountVo
    })
    return { fishCountVo }
}

export async function ApiGetNightingale() {
    let aquarium = sessionStorage.getItem('aquarium')
    let resList = reactive([])
    await httpRequest.get(`/web/index/fishProportion/${aquarium}`).then((res) => {
        resList = res.data.data.resList
    })
    return { resList }
}

export async function ApiGetLine() {
    let aquarium = sessionStorage.getItem('aquarium')
    let data = reactive({ diandao: [], hunzhuo: [], ph: [], wendu: [], listWeek: [] })
    await httpRequest.get(`/web/index/oneWeekWaterSta/${aquarium}`).then((res) => {
        data = res.data.data
    })
    return { data }
}

export async function ApiGetPie() {
    let aquarium = sessionStorage.getItem('aquarium')
    let stateCountList = reactive([])
    await httpRequest.get(`/web/index/fishStateCircle/${aquarium}`).then((res) => {
        stateCountList = res.data.data.stateCountList
    })
    return { stateCountList }
}

export async function ApiGetProgress() {
    let aquarium = sessionStorage.getItem('aquarium')
    let curCount = 0;
    let maxCount = 0;
    let deathCount = 0;
    let illCount = 0;
    let normalCount = 0;
    await httpRequest.get(`/web/index/fishProgress/${aquarium}`).then((res) => {
        maxCount = res.data.data.maxCount;
        curCount = res.data.data.curCount;
        deathCount = res.data.data.stateCountList[0].value;
        illCount = res.data.data.stateCountList[1].value;
        normalCount = res.data.data.stateCountList[2].value;
    })
    return {
        maxCount,
        curCount,
        deathCount,
        illCount,
        normalCount
    }
}

export async function ApiGetEquipment() {
    let aquarium = sessionStorage.getItem('aquarium')
    let EquipmentList: EquipmentListParm[] = reactive([]);
    const { data: res } = await httpRequest.get(`/web/equipment/getEquipment/${aquarium}`)
    if (res) {
        EquipmentList.push(...res.data.EquipmentList);
    }
    return EquipmentList
}

export async function ApiGetMessages() {
    let aquarium = sessionStorage.getItem('aquarium')
    const { data: res } = await httpRequest.get(`/web/aquarium/aquariumMess/${aquarium}`)
    let aquariumMess:aquariumMessageParm = res.data.aquariumMess
    return aquariumMess
}

export async function ApiGetIncreaseAndDecrease() {
    let aquarium = sessionStorage.getItem('aquarium')
    let increaseAndDecrease = reactive({ xAxis: [], yAxis1: [], yAxis2: [] })
    const { data: res } = await httpRequest.get(`/web/index/increaseAndDecrease/${aquarium}/5`)
    increaseAndDecrease = res.data
    return increaseAndDecrease
}